<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css"/>




  <link href="http://7xsody.com1.z0.glb.clouddn.com/H2DMvhDLycM56KNuAtbJYA.woff2" rel="stylesheet" type="text/css">



<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=0.5.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="唯中科技," />





  <link rel="alternate" href="/atom.xml" title="ANIMO!" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=0.5.0" />






<meta name="description" content="逻辑梳理：">
<meta property="og:type" content="article">
<meta property="og:title" content="日志分表">
<meta property="og:url" content="https://leptune.github.io/2016/04/06/log-sep/index.html">
<meta property="og:site_name" content="ANIMO!">
<meta property="og:description" content="逻辑梳理：">
<meta property="og:updated_time" content="2016-04-06T07:30:32.841Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="日志分表">
<meta name="twitter:description" content="逻辑梳理：">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"left","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 6270251983022589000,
      author: '博主'
    }
  };
</script>

  <title> 日志分表 | ANIMO! </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  



  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?8bd1e3d6bfebd2a0429a42029654896e";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>








  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">ANIMO!</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">FIGHT!</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-home fa-fw"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-archive fa-fw"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-tags fa-fw"></i> <br />
            
            标签
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="#" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>


    </div>
  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                日志分表
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2016-04-06T11:52:45+09:00" content="2016-04-06">
              2016-04-06
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/工作日志/" itemprop="url" rel="index">
                    <span itemprop="name">工作日志</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
              <span class="post-comments-count">
                &nbsp; | &nbsp;
                <a href="/2016/04/06/log-sep/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2016/04/06/log-sep/" itemprop="commentsCount"></span>
                </a>
              </span>
            
          

          

          
          
             <span id="/2016/04/06/log-sep/" class="leancloud_visitors" data-flag-title="日志分表">
               &nbsp; | &nbsp;
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               <span class="post-meta-item-text">阅读次数 </span>
               <span class="leancloud-visitors-count"></span>
              </span>
          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>逻辑梳理：<br><a id="more"></a></p>
<h2 id="直接运行下面的php代码便可得到所有表的分表sql语句："><a href="#直接运行下面的php代码便可得到所有表的分表sql语句：" class="headerlink" title="直接运行下面的php代码便可得到所有表的分表sql语句："></a>直接运行下面的php代码便可得到所有表的分表sql语句：</h2><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?php</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">gen_partion_log</span><span class="params">($tables, $db_name)</span> </span>&#123;</span><br><span class="line">    $sql = <span class="string">''</span>;</span><br><span class="line">    <span class="keyword">foreach</span> ($tables <span class="keyword">as</span> $tb) &#123;</span><br><span class="line">        $sql .= <span class="string">&lt;&lt;&lt;EOF</span><br><span class="line">-- 建立临时分区表：</span><br><span class="line">-- 拷贝表结构：</span><br><span class="line">Delimiter ;</span><br><span class="line">drop table if exists <span class="subst">&#123;$tb['name']&#125;</span>_tmp;</span><br><span class="line">create table <span class="subst">&#123;$tb['name']&#125;</span>_tmp like <span class="subst">&#123;$tb['name']&#125;</span>;</span><br><span class="line">-- RANGE COLUMNS分区要求分区列不能是varchar类型，所以，要将add_time改为int类型：</span><br><span class="line">ALTER TABLE `<span class="subst">&#123;$tb['name']&#125;</span>_tmp` CHANGE COLUMN `<span class="subst">&#123;$tb['timefield']&#125;</span>` `<span class="subst">&#123;$tb['timefield']&#125;</span>` INT NOT NULL COMMENT '添加时间-时间戳';</span><br><span class="line">-- 分区列必须包含在主键里，所以要将<span class="subst">&#123;$tb['timefield']&#125;</span>包含进主键：</span><br><span class="line">ALTER TABLE `<span class="subst">&#123;$tb['name']&#125;</span>_tmp`    DROP PRIMARY KEY,  ADD PRIMARY KEY (`id`, `<span class="subst">&#123;$tb['timefield']&#125;</span>`);</span><br><span class="line">-- 增加分区（按月分区）：</span><br><span class="line">ALTER TABLE `<span class="subst">&#123;$tb['name']&#125;</span>_tmp`  PARTITION BY RANGE COLUMNS(<span class="subst">&#123;$tb['timefield']&#125;</span>)</span><br><span class="line">(PARTITION p201511 VALUES LESS THAN (UNIX_TIMESTAMP('2015-12-01')),</span><br><span class="line"> PARTITION p201512 VALUES LESS THAN (UNIX_TIMESTAMP('2016-01-01')),</span><br><span class="line"> PARTITION p201601 VALUES LESS THAN (UNIX_TIMESTAMP('2016-02-01')),</span><br><span class="line"> PARTITION p201602 VALUES LESS THAN (UNIX_TIMESTAMP('2016-03-01')),</span><br><span class="line"> PARTITION p201603 VALUES LESS THAN (UNIX_TIMESTAMP('2016-04-01')),</span><br><span class="line"> PARTITION p201604 VALUES LESS THAN (UNIX_TIMESTAMP('2016-05-01')),</span><br><span class="line"> PARTITION p201605 VALUES LESS THAN (UNIX_TIMESTAMP('2016-06-01'))</span><br><span class="line"> );</span><br><span class="line"></span><br><span class="line">-- 从<span class="subst">&#123;$tb['name']&#125;</span>表中导入数据：</span><br><span class="line">insert into <span class="subst">&#123;$tb['name']&#125;</span>_tmp select * from <span class="subst">&#123;$tb['name']&#125;</span>;</span><br><span class="line">-- 将临时表和正式表互换：</span><br><span class="line">drop table if exists <span class="subst">&#123;$tb['name']&#125;</span>_older;</span><br><span class="line">rename table <span class="subst">&#123;$tb['name']&#125;</span> to <span class="subst">&#123;$tb['name']&#125;</span>_older;</span><br><span class="line">rename table <span class="subst">&#123;$tb['name']&#125;</span>_tmp to <span class="subst">&#123;$tb['name']&#125;</span>;</span><br><span class="line"></span><br><span class="line">-- 创建数据库定时任务（每个月的1号的凌晨1点执行上面创建的存储器）：</span><br><span class="line">DELIMITER $$</span><br><span class="line">DROP EVENT IF EXISTS `eSetPartition_<span class="subst">&#123;$tb['name']&#125;</span>`;</span><br><span class="line">$$</span><br><span class="line">CREATE EVENT eSetPartition_<span class="subst">&#123;$tb['name']&#125;</span></span><br><span class="line">ON SCHEDULE EVERY 1 MONTH STARTS DATE_ADD(DATE_ADD(DATE_SUB(CURDATE(),INTERVAL DAY(CURDATE())-1 DAY), INTERVAL 1 MONTH),INTERVAL 1 HOUR)   </span><br><span class="line">ON COMPLETION PRESERVE ENABLE  </span><br><span class="line">COMMENT '对<span class="subst">&#123;$tb['name']&#125;</span>表每个月1号的凌晨1点自动执行分区' </span><br><span class="line">DO</span></span><br><span class="line">BEGIN</span><br><span class="line">    call SetPartitionTimestamp(<span class="string">'&#123;$tb['</span>name<span class="string">']&#125;'</span>);</span><br><span class="line">END;</span><br><span class="line">$$</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">EOF;</span><br><span class="line">    &#125;</span><br><span class="line">    $sql .= <span class="string">&lt;&lt;&lt;EOF</span><br><span class="line">-- 创建存储过程来自动为每个月创建分区：</span><br><span class="line">DELIMITER $$</span><br><span class="line">DROP PROCEDURE IF EXISTS `SetPartitionTimestamp`;</span><br><span class="line">$$</span><br><span class="line">CREATE PROCEDURE SetPartitionTimestamp(IN tb_name varchar(30))</span><br><span class="line">COMMENT '对timestamp字段类型按每个月划分分区'</span><br><span class="line">BEGIN</span></span><br><span class="line">    SET @db_name = <span class="string">'&#123;$db_name&#125;'</span>;</span><br><span class="line">    SET @part_prefix = <span class="string">'p'</span>;</span><br><span class="line">    SELECT REPLACE(partition_name,@part_prefix,<span class="string">''</span>) INTO @last_year_mon</span><br><span class="line">        FROM INFORMATION_SCHEMA.PARTITIONS</span><br><span class="line">        WHERE TABLE_SCHEMA=@db_name <span class="keyword">AND</span> table_name=tb_name</span><br><span class="line">        ORDER BY partition_ordinal_position DESC</span><br><span class="line">        LIMIT <span class="number">1</span>;</span><br><span class="line">    select PERIOD_ADD(@last_year_mon,<span class="number">1</span>) into @next_year_mon;</span><br><span class="line">    select PERIOD_ADD(@next_year_mon,<span class="number">1</span>) into @next_next_year_mon;</span><br><span class="line">    SET @exec_sql = CONCAT(<span class="string">'ALTER TABLE `'</span>, tb_name, <span class="string">'` ADD PARTITION (PARTITION '</span>, @part_prefix, @next_year_mon, <span class="string">' VALUES LESS THAN (UNIX_TIMESTAMP(\''</span>, @next_next_year_mon, <span class="string">'01\')))'</span>);</span><br><span class="line">    PREPARE stmt2 FROM @exec_sql;</span><br><span class="line">    EXECUTE stmt2;</span><br><span class="line">    DEALLOCATE PREPARE stmt2;</span><br><span class="line">END;</span><br><span class="line">$$</span><br><span class="line">-- 开启event：</span><br><span class="line">SET <span class="keyword">GLOBAL</span> event_scheduler = ON;</span><br><span class="line">SET @@<span class="keyword">global</span>.event_scheduler = ON;</span><br><span class="line">SET <span class="keyword">GLOBAL</span> event_scheduler = <span class="number">1</span>;</span><br><span class="line">SET @@<span class="keyword">global</span>.event_scheduler = <span class="number">1</span>;</span><br><span class="line">$$</span><br><span class="line">EOF;</span><br><span class="line">    <span class="keyword">return</span> $sql;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">$tables = [ <span class="comment">// 表名、分列字段</span></span><br><span class="line">    [<span class="string">'name'</span> =&gt; <span class="string">'dx_zhushou_update_log'</span>   , <span class="string">'timefield'</span> =&gt; <span class="string">'updateDate'</span>],</span><br><span class="line">    [<span class="string">'name'</span> =&gt; <span class="string">'dx_zhushou_uninstall_log'</span>, <span class="string">'timefield'</span> =&gt; <span class="string">'updateDate'</span>],</span><br><span class="line">    [<span class="string">'name'</span> =&gt; <span class="string">'dx_zhushou_run_log'</span>      , <span class="string">'timefield'</span> =&gt; <span class="string">'updateDate'</span>],</span><br><span class="line">    [<span class="string">'name'</span> =&gt; <span class="string">'dx_zhushou_install_log'</span>  , <span class="string">'timefield'</span> =&gt; <span class="string">'updateDate'</span>],</span><br><span class="line">    [<span class="string">'name'</span> =&gt; <span class="string">'dx_zhushou_down_log'</span>     , <span class="string">'timefield'</span> =&gt; <span class="string">'downDate'</span>  ],</span><br><span class="line">    [<span class="string">'name'</span> =&gt; <span class="string">'dx_syb_down_log'</span>         , <span class="string">'timefield'</span> =&gt; <span class="string">'downDate'</span>  ],</span><br><span class="line">    [<span class="string">'name'</span> =&gt; <span class="string">'dx_simulator_run_log'</span>    , <span class="string">'timefield'</span> =&gt; <span class="string">'updateDate'</span>],</span><br><span class="line">    [<span class="string">'name'</span> =&gt; <span class="string">'dx_simulator_install_log'</span>, <span class="string">'timefield'</span> =&gt; <span class="string">'updateDate'</span>],</span><br><span class="line">    [<span class="string">'name'</span> =&gt; <span class="string">'dx_phone_install_log'</span>    , <span class="string">'timefield'</span> =&gt; <span class="string">'updateDate'</span>],</span><br><span class="line">    [<span class="string">'name'</span> =&gt; <span class="string">'dx_game_log'</span>             , <span class="string">'timefield'</span> =&gt; <span class="string">'add_time'</span>  ],</span><br><span class="line">];</span><br><span class="line"></span><br><span class="line"><span class="keyword">echo</span> gen_partion_log($tables, <span class="string">'scp_shuowan_tj_local'</span>).<span class="string">"\n"</span>;</span><br></pre></td></tr></table></figure>
<h2 id="运行下面的sql语句可用于查询分表后的性能"><a href="#运行下面的sql语句可用于查询分表后的性能" class="headerlink" title="运行下面的sql语句可用于查询分表后的性能"></a>运行下面的sql语句可用于查询分表后的性能</h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">--查看插入的数据是否有按分区存放：</span></span><br><span class="line">Delimiter ;</span><br><span class="line"><span class="keyword">SELECT</span> PARTITION_NAME <span class="keyword">as</span> 分区名,PARTITION_ORDINAL_POSITION <span class="keyword">as</span> 分区顺序, PARTITION_DESCRIPTION <span class="keyword">as</span> 分区条件, TABLE_ROWS <span class="keyword">as</span> 分区行数</span><br><span class="line"><span class="keyword">FROM</span> information_schema.PARTITIONS </span><br><span class="line"><span class="keyword">WHERE</span> TABLE_SCHEMA=<span class="string">'scp_shuowan_tj_local'</span> <span class="keyword">AND</span> TABLE_NAME = <span class="string">'dx_game_log'</span>;</span><br><span class="line"><span class="comment">--对比分区前后查询速度：</span></span><br><span class="line"><span class="comment">--分区前的查询速度（结果：查询时间约0.4s）：</span></span><br><span class="line"><span class="keyword">select</span> <span class="keyword">count</span>(*) <span class="keyword">from</span> dx_game_log_older <span class="keyword">where</span> add_time &gt;= <span class="keyword">unix_timestamp</span>(<span class="string">'2016-03-01'</span>) <span class="keyword">and</span> add_time &lt; <span class="keyword">unix_timestamp</span>(<span class="string">'2016-04-01'</span>);</span><br><span class="line"><span class="comment">--分区后的查询速度（结果：查询时间约0.1s）：</span></span><br><span class="line"><span class="keyword">select</span> <span class="keyword">count</span>(*) <span class="keyword">from</span> dx_game_log <span class="keyword">where</span> add_time &gt;= <span class="keyword">unix_timestamp</span>(<span class="string">'2016-03-01'</span>) <span class="keyword">and</span> add_time &lt; <span class="keyword">unix_timestamp</span>(<span class="string">'2016-04-01'</span>);</span><br><span class="line"><span class="comment">--查看分区后，执行的查询有扫描哪些分区（结果：只扫描了p201603分区。若将&lt;改为&lt;=，则会扫描p201603,p201604两个分区）：</span></span><br><span class="line"><span class="keyword">explain</span> <span class="keyword">partitions</span> <span class="keyword">select</span> <span class="keyword">count</span>(*) <span class="keyword">from</span> dx_game_log <span class="keyword">where</span> add_time &gt;= <span class="keyword">unix_timestamp</span>(<span class="string">'2016-03-01'</span>) <span class="keyword">and</span> add_time &lt; <span class="keyword">unix_timestamp</span>(<span class="string">'2016-04-01'</span>);</span><br></pre></td></tr></table></figure>
<h2 id="确认无误后，删除旧的未分表的表："><a href="#确认无误后，删除旧的未分表的表：" class="headerlink" title="确认无误后，删除旧的未分表的表："></a>确认无误后，删除旧的未分表的表：</h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">Delimiter ;</span><br><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> <span class="keyword">if</span> <span class="keyword">exists</span> dx_zhushou_update_log_older;</span><br><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> <span class="keyword">if</span> <span class="keyword">exists</span> dx_zhushou_uninstall_log_older;</span><br><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> <span class="keyword">if</span> <span class="keyword">exists</span> dx_zhushou_run_log_older;</span><br><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> <span class="keyword">if</span> <span class="keyword">exists</span> dx_zhushou_install_log_older;</span><br><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> <span class="keyword">if</span> <span class="keyword">exists</span> dx_zhushou_down_log_older;</span><br><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> <span class="keyword">if</span> <span class="keyword">exists</span> dx_syb_down_log_older;</span><br><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> <span class="keyword">if</span> <span class="keyword">exists</span> dx_simulator_run_log_older;</span><br><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> <span class="keyword">if</span> <span class="keyword">exists</span> dx_simulator_install_log_older;</span><br><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> <span class="keyword">if</span> <span class="keyword">exists</span> dx_phone_install_log_older;</span><br><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> <span class="keyword">if</span> <span class="keyword">exists</span> dx_game_log_older;</span><br></pre></td></tr></table></figure>
<hr>

      
    </div>
    
    <div>
      
        
      
    </div>

    <div>
      
        
<div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton", disable="enable", onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}", style="cursor: pointer; border: 0; outline: 0; border-radius: 100%; padding: 0; margin: 0; letter-spacing: normal; text-transform: none; text-indent: 0px; text-shadow: none">
    <span onmouseover="this.style.color='rgb(236,96,0)';this.style.background='rgb(204,204,204)'" onMouseOut="this.style.color='#fff';this.style.background='rgb(236,96,0)'" style="display: inline-block; width: 70px; height: 70px; border-radius: 100%; line-height: 81px; color: #fff; font: 400 35px/75px 'microsofty'; background: rgb(236,96,0)">赏</span>
  </button>
  <div id="QR" style="display: none;">
    
    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="http://7xsody.com2.z0.glb.clouddn.com/mypay.jpg" alt="Leptune Alipay" style="width: 200px; max-width: 100%; display: inline-block"/>
        <p>支付宝打赏</p>
      </div>
    
  </div>
</div>

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/唯中科技/" rel="tag">#唯中科技</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/04/06/hello-world/" rel="next" title="Hello World leptune">
                <i class="fa fa-chevron-left"></i> Hello World leptune
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
        
<script>
  with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];
</script>

      
    </div>
  </div>


          </div>
          

  <p>热评文章</p>
  <div class="ds-top-threads" data-range="weekly" data-num-items="4"></div>


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2016/04/06/log-sep/"
           data-title="日志分表" data-url="https://leptune.github.io/2016/04/06/log-sep/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="http://7xsody.com2.z0.glb.clouddn.com/avatar.jpg"
               alt="Leptune" />
          <p class="site-author-name" itemprop="name">Leptune</p>
          <p class="site-description motion-element" itemprop="description">好好学习，天天向上！</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">2</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              
                <span class="site-state-item-count">1</span>
                <span class="site-state-item-name">分类</span>
              
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">1</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/leptune" target="_blank">
                  
                    <i class="fa fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        <div class="links-of-blogroll motion-element">
          
            <div class="links-of-blogroll-title">友情链接</div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="http://theme-next.iissnan.com/" target="_blank">Hexo-Next主题</a>
                </li>
              
            </ul>
          
        </div>

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#直接运行下面的php代码便可得到所有表的分表sql语句："><span class="nav-number">1.</span> <span class="nav-text">直接运行下面的php代码便可得到所有表的分表sql语句：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#运行下面的sql语句可用于查询分表后的性能"><span class="nav-number">2.</span> <span class="nav-text">运行下面的sql语句可用于查询分表后的性能</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#确认无误后，删除旧的未分表的表："><span class="nav-number">3.</span> <span class="nav-text">确认无误后，删除旧的未分表的表：</span></a></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  1989 - 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Leptune</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="http://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>
<div class="theme-info">
  <span id="busuanzi_container_site_pv" style="display:none;">
      &nbsp;&nbsp;|&nbsp;&nbsp;您是本站的第<span id="busuanzi_value_site_pv" style="color:red;font-size: medium;font-weight: bold;"></span>位访问者&nbsp;&nbsp;|
  </span>
</div>
<script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">

</script>


      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  


  




<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>


  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  <script type="text/javascript" src="/vendors/velocity/velocity.min.js"></script>

  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js"></script>

  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=0.5.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=0.5.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=0.5.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=0.5.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=0.5.0"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"leptune"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
      <script src="/vendors/ua-parser-js/dist/ua-parser.min.js"></script>
      <script src="/js/src/hook-duoshuo.js"></script>
    
  





  
  
  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
       search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body").append('<div class="popoverlay">').css('overflow', 'hidden');
      $('.popup').toggle();

    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
    'use strict';
    $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
            // get the contents from search data
            isfetched = true;
            $('.popup').detach().appendTo('.header-inner');
            var datas = $( "entry", xmlResponse ).map(function() {
                return {
                    title: $( "title", this ).text(),
                    content: $("content",this).text(),
                    url: $( "url" , this).text()
                };
            }).get();
            var $input = document.getElementById(search_id);
            var $resultContent = document.getElementById(content_id);
            $input.addEventListener('input', function(){
                var matchcounts = 0;
                var str='<ul class=\"search-result-list\">';                
                var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                $resultContent.innerHTML = "";
                if (this.value.trim().length > 1) {
                // perform local searching
                datas.forEach(function(data) {
                    var isMatch = true;
                    var content_index = [];
                    var data_title = data.title.trim().toLowerCase();
                    var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                    var data_url = data.url;
                    var index_title = -1;
                    var index_content = -1;
                    var first_occur = -1;
                    // only match artiles with not empty titles and contents
                    if(data_title != '' && data_content != '') {
                        keywords.forEach(function(keyword, i) {
                            index_title = data_title.indexOf(keyword);
                            index_content = data_content.indexOf(keyword);
                            if( index_title < 0 && index_content < 0 ){
                                isMatch = false;
                            } else {
                                if (index_content < 0) {
                                    index_content = 0;
                                }
                                if (i == 0) {
                                    first_occur = index_content;
                                }
                            }
                        });
                    }
                    // show search results
                    if (isMatch) {
                        matchcounts += 1;
                        str += "<li><a href='"+ data_url +"' class='search-result-title'>"+ data_title +"</a>";
                        var content = data.content.trim().replace(/<[^>]+>/g,"");
                        if (first_occur >= 0) {
                            // cut out 100 characters
                            var start = first_occur - 20;
                            var end = first_occur + 80;
                            if(start < 0){
                                start = 0;
                            }
                            if(start == 0){
                                end = 50;
                            }
                            if(end > content.length){
                                end = content.length;
                            }
                            var match_content = content.substring(start, end);
                            // highlight all keywords
                            keywords.forEach(function(keyword){
                                var regS = new RegExp(keyword, "gi");
                                match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                            });
                            
                            str += "<p class=\"search-result\">" + match_content +"...</p>"
                        }
                        str += "</li>";
                    }
                })};
                str += "</ul>";
                if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
                if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
                $resultContent.innerHTML = str;
            });
            proceedsearch();
        }
    });}

    // handle and trigger popup window;
    $('.popup-trigger').mousedown(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };

    });

    $('.popup-btn-close').click(function(e){
      $('.popup').hide();
      $(".popoverlay").remove();
      $('body').css('overflow', '');
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>

  

  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
  <script>AV.initialize("O7PCcqOYYgCaMydM2oJf770L-gzGzoHsz", "fCVOffUgYz01swVimC1aMq2F");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

</body>
</html>
